<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('货位统计表列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>仓库：</label>
                            <select name="warehouseId" th:with="type=${@dict.getType('is_house')}" required>
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search('formId','bootstrap-table')"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset('formId','bootstrap-table')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <!--                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="search:viewCargoStatistics:add">-->
            <!--                    <i class="fa fa-plus"></i> 添加-->
            <!--                </a>-->
            <!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="search:viewCargoStatistics:edit">-->
            <!--                    <i class="fa fa-edit"></i> 修改-->
            <!--                </a>-->
            <!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="search:viewCargoStatistics:remove">-->
            <!--                    <i class="fa fa-remove"></i> 删除-->
            <!--                </a>-->
            <a class="btn btn-warning" onclick="$.table.exportExcel()" >
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('search:viewCargoStatistics:edit')}]];
    var removeFlag = [[${@permission.hasPermi('search:viewCargoStatistics:remove')}]];
    var warehouse = [[${@dict.getType('is_house')}]];
    var prefix = ctx + "search/viewCargoStatistics";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "货位统计表",
            pageSize:15,
            onPostBody:function (){
                $('#bootstrap-table').bootstrapTable('mergeCells',{
                    index:0,
                    field:'warehouseId',
                    rowspan:7


                });
                $('#bootstrap-table').bootstrapTable('mergeCells',{
                    index:7,
                    field:'warehouseId',
                    rowspan:4


                });
            },
            clickToSelect: true,//是否启用点击选中行
            uniqueId:"warehouseId",//表主键(用于修改和删除)
            sortName:"warehouseId",//必加排序 sortOrder: "asc"默认
            columns: [
                {
                    halign: 'center',
                    align:'center',
                    checkbox: true
                },
                {
                    title: "序号",
                    halign: 'center',
                    align:'center',
                    width: 55,
                    formatter:function (value, row, index) {
                        //获取每页显示的数量
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;
                        //获取当前是第几页
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;
                        //返回序号，注意index是从0开始的，所以要加上1
                        return pageSize * (pageNumber - 1) + index + 1;

                    }
                },

                {
                    field: 'warehouseId',
                    title: '仓库',
                    halign: 'center',
                    align:'center',
                    sortable: true,
                    visible: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(warehouse, value);

                    }
                },
                {
                    field: 'roadwayId',
                    title: '巷道',
                    halign: 'center',
                    align:'center',
                    sortable: true,
                    visible: true
                },
                {
                    field: 'fullCargo',
                    title: '有物资',
                    halign: 'center',
                    align:'center',
                    sortable: true,
                    visible: true
                },
                {
                    field: 'emptyCargo',
                    title: '空物资',
                    halign: 'center',
                    align:'center',
                    sortable: true,
                    visible: true
                },
                {
                    field: 'allCargo',
                    title: '总计',
                    halign: 'center',
                    align:'center',
                    sortable: true,
                    visible: true
                },
                // {
                //     title: '操作',
                //     halign: 'center',
                //     align: 'center',
                //     formatter: function(value, row, index) {
                //         var actions = [];
                //         actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.warehouseId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                //         actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.warehouseId + '\')"><i class="fa fa-remove"></i>删除</a>');
                //         return actions.join('');
                //     }
                // }
            ]
        };
        $.table.init(options);
    });

    // setTimeout(autoCombineAll, 2000);

    // /**
    //  *
    //  * @param target 目标表单,用若依框架的可以直接这样用
    //  * 或者表单已经渲染上去的可以,把目标表单放上来(个人封装,不推荐)
    //  */
    // function autoCombineAll(){
    //     var target=$("#bootstrap-table")
    //     // alert("!!!!!")
    //     let data=target.bootstrapTable("getData");
    //     let params=Object.keys(data[0]);
    //     for (const paramsKey in params) {
    //         combineRowByName(data,target,params[paramsKey]);
    //     }
    // }
    //
    // /**
    //  *
    //  * @param data 目标数据源,也就是表单数据,要数组类型
    //  * @param target 需要修改的表单
    //  * @param fieldName 需要合并的列名
    //  */
    // function combineRowByName(data,target,fieldName){
    //     //初始位置集合
    //     let firstIndexs=[];
    //     //对应合并的长度
    //     let publicRowNumbers=[];
    //     //开始位置
    //     let firstIndex=0;
    //     //共有值,对照数组
    //     let publicRow=data[0][fieldName];
    //     //当前共有值数量
    //     let publicRowNumber=0;
    //     for (let i = 0; i < data.length; i++) {
    //         if(publicRow===data[i][fieldName]){//如果同行相等,则长度增加
    //             publicRowNumber++;
    //         }else{//不相等
    //             if(publicRowNumber>1){//超过一个则合并到一起,保存
    //                 firstIndexs.push(firstIndex);
    //                 publicRowNumbers.push(publicRowNumber);
    //             }
    //             //重置数量,共有值,初始值
    //             publicRowNumber=1;
    //             publicRow=data[i][fieldName];
    //             firstIndex=i;
    //         }
    //         if(i===data.length-1){//结束时在进行一次判断
    //             if(publicRowNumber>1){
    //                 firstIndexs.push(firstIndex);
    //                 publicRowNumbers.push(publicRowNumber);
    //             }
    //             //重置数量,共有值,初始值
    //             publicRowNumber=1;
    //             publicRow=data[i][fieldName];
    //             firstIndex=i;
    //         }
    //     }
    //     for (let i = 0; i < firstIndexs.length; i++) {//循环修改表单
    //         target.bootstrapTable('mergeCells', {
    //             index: firstIndexs[i],
    //             field: fieldName,
    //             colspan: 1,
    //             rowspan: publicRowNumbers[i]
    //         });
    //     }
    // }
</script>
</body>
</html>